<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Companies and connections</title>
    <style>
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            background-color: #f4f7f6;
            color: #333;
            margin: 0;
            padding: 20px;
        }
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }
        h2 {
            color: #4CAF50;
            cursor: pointer;
        }
        .block {
            background-color: #fff;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        .hidden {
            display: none;
        }
        label {
            font-weight: bold;
        }
        input[type="text"], select {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        button:disabled {
            background-color: #ccc;
            cursor: not-allowed;
        }
        button:hover:enabled {
            background-color: #45a049;
        }
        #company-list {
            margin-top: 10px;
        }
        .company-card {
            background-color: #fafafa;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            margin-bottom: 10px;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            transition: background-color 0.5s ease;
        }
        .highlight {
            background-color: #d4edda !important;
        }
        .company-name {
            flex-grow: 1;
            text-align: left;
        }
        .company-name a {
            color: #3498db;
            text-decoration: none;
            font-weight: bold;
        }
        .company-connections {
            display: flex;
            flex-direction: column;
            text-align: right;
            margin-right: 20px;
            flex-grow: 2;
        }
        .company-connections a {
            color: #3498db;
            text-decoration: none;
            margin-bottom: 5px;
        }
        .company-actions {
            text-align: right;
        }
        .company-actions button {
            background-color: #e74c3c;
            padding: 5px 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            color: white;
            transition: background-color 0.3s ease;
        }
        .company-actions button:hover {
            background-color: #c0392b;
        }
    </style>
</head>
<body>

    <!-- Title of the page -->
    <h1>Companies and connections</h1>

    <!-- Block 1: Manage Connections -->
    <div class="block">
        <h2 id="manage-connections-header">Manage Connections</h2>
        <div id="manage-connections-content">
            <label for="keywords">Keywords:</label>
            <input type="text" id="keywords" name="keywords" placeholder="Enter keywords...">
            <br><br>
            <label for="location">Location:</label>
            <select id="location" name="location">
                <option value="global">Global</option>
                <option value="usa">USA</option>
                <option value="europe">Europe</option>
                <!-- Load more locations as needed -->
            </select>
            <br><br>
            <button id="update-connections">Update connections</button>
        </div>
    </div>

    <!-- Block 2: Load Company -->
    <div class="block">
        <h2 id="add-company-header">Add Company</h2>
        <div id="add-company-content">
            <label for="company-name">Company name:</label>
            <input type="text" id="company-name" name="company-name" placeholder="Enter company name...">
            <br><br>
            <button id="add-company" disabled>Add</button>
        </div>
    </div>

    <!-- Block 3: Company List -->
    <div class="block hidden" id="company-list-block">
        <h2>Company List</h2>
        <div id="company-list">
            <!-- Company cards will be dynamically added here -->
        </div>
    </div>

    <script>
        {
            // Manage Connections toggle
            const $manageConnectionsHeader = document.getElementById('manage-connections-header');
            const $manageConnectionsContent = document.getElementById('manage-connections-content');
            $manageConnectionsHeader.addEventListener('click', () => {
                $manageConnectionsContent.classList.toggle('hidden');
            });

            // Load Company toggle
            const $addCompanyHeader = document.getElementById('add-company-header');
            const $addCompanyContent = document.getElementById('add-company-content');
            $addCompanyHeader.addEventListener('click', () => {
                $addCompanyContent.classList.toggle('hidden');
            });

            // Load company functionality and show Company List when there's at least one company
            const companyList = document.getElementById('company-list');
            const companyListBlock = document.getElementById('company-list-block');
            const companyNameInput = document.getElementById('company-name');
            const addCompanyButton = document.getElementById('add-company');

            // Enable/Disable Load button based on input
            companyNameInput.addEventListener('input', function() {
                if (companyNameInput.value.trim() !== '') {
                    addCompanyButton.removeAttribute('disabled');
                } else {
                    addCompanyButton.setAttribute('disabled', 'disabled');
                }
            });

            // Function to temporarily highlight the new company card
            function highlightCard(card) {
                card.classList.add('highlight');
                setTimeout(() => {
                    card.classList.remove('highlight');
                }, 2000); // Highlight lasts for 2 seconds
            }

            // Load Company button click event
            addCompanyButton.addEventListener('click', function() {
                const companyName = companyNameInput.value;
                if (companyName) {
                    // Create a new company card
                    const card = document.createElement('div');
                    card.className = 'company-card';

                    // Create company name container
                    const companyNameContainer = document.createElement('div');
                    companyNameContainer.className = 'company-name';
                    const companyLink = document.createElement('a');
                    companyLink.href = 'javascript:void(0);';
                    companyLink.innerText = companyName;
                    companyNameContainer.appendChild(companyLink);
                    card.appendChild(companyNameContainer);

                    // Create connections container
                    const companyConnectionsContainer = document.createElement('div');
                    companyConnectionsContainer.className = 'company-connections';
                    const connections = ['1st', '2nd', '1st X', '2nd X'];
                    connections.forEach(conn => {
                        const connLink = document.createElement('a');
                        connLink.href = 'javascript:void(0);';
                        connLink.innerText = `Connections ${conn}`;
                        companyConnectionsContainer.appendChild(connLink);
                    });
                    card.appendChild(companyConnectionsContainer);

                    // Create actions container (delete button)
                    const companyActionsContainer = document.createElement('div');
                    companyActionsContainer.className = 'company-actions';
                    const deleteButton = document.createElement('button');
                    deleteButton.innerText = 'Delete';
                    deleteButton.addEventListener('click', function() {
                        card.remove();
                        // Hide Company List if no companies are left
                        if (!companyList.hasChildNodes()) {
                            companyListBlock.classList.add('hidden');
                        }
                    });
                    companyActionsContainer.appendChild(deleteButton);
                    card.appendChild(companyActionsContainer);

                    // Append card to company list
                    companyList.appendChild(card);

                    // Highlight the new company card
                    highlightCard(card);

                    // Show Company List block when there's at least one company
                    if (companyList.children.length > 0) {
                        companyListBlock.classList.remove('hidden');
                    }

                    // Clear input field and disable Load button
                    companyNameInput.value = '';
                    addCompanyButton.setAttribute('disabled', 'disabled');
                }
            });
        }
    </script>
</body>
</html>
